﻿using EntityModels.Entities;
using Microsoft.EntityFrameworkCore;

namespace EntityModels.DbContexts
{
    /// <summary>
    /// 主键
    /// </summary>
    public class EntityKeyDbContext : DbContext
    {
        public DbSet<SimpleKeyEntity> simpleKeyEntities => Set<SimpleKeyEntity>();

        public DbSet<CompositeKeyEntity> compositeKeyEntities => Set<CompositeKeyEntity>();
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CompositeKeyEntity>()
                .HasKey(c => new { c.KeyPart1, c.KeyPart2 })
                .HasName("CompositePrimaryKey");
        }

    }
}
